// -----------------------------------------------------------------------
//  <copyright file="HasDomainEventEntityBase.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2023 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2023-12-16 18:00</last-date>
// -----------------------------------------------------------------------

using System.ComponentModel.DataAnnotations.Schema;


namespace DaprPlus.Domain.Entity;

/// <summary>
/// 包含领域事件的实体基类
/// </summary>
public abstract class HasDomainEventEntityBase : EntityBase, IHasDomainEvent
{
    [NotMapped]
    protected readonly List<DomainEvent> _DomainEvents = new();

    /// <summary>
    /// 领域事件集合
    /// </summary>
    [NotMapped]
    public IReadOnlyList<DomainEvent> DomainEvents => _DomainEvents.AsReadOnly();

    public void AddDomainEvent(DomainEvent domainEvent)
    {
        _DomainEvents.Add(domainEvent);
    }

    /// <summary>
    /// 清空当前实体内的领域事件
    /// </summary>
    public void ClearDomainEvents()
    {
        _DomainEvents.Clear();
    }
}
